package com.hyc.seckillsystem.service.Impl;

import com.hyc.seckillsystem.dao.GoodsMapper;
import com.hyc.seckillsystem.dao.SeckillGoodsMapper;
import com.hyc.seckillsystem.dao.orderMapper;
import com.hyc.seckillsystem.pojo.SeckillGoods;
import com.hyc.seckillsystem.pojo.goods;
import com.hyc.seckillsystem.pojo.order;
import com.hyc.seckillsystem.service.orderService;
import com.hyc.seckillsystem.vo.orderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @projectName: seckillsystem
 * @package: com.hyc.seckillsystem.service.Impl
 * @className: orderServiceImpl
 * @author: 冷环渊 doomwatcher
 * @description: TODO
 * @date: 2022/3/8 13:58
 * @version: 1.0
 */
@Service
public class orderServiceImpl implements orderService {
    @Autowired
    GoodsMapper goodsMapper;
    @Autowired
    SeckillGoodsMapper seckillGoodsMapper;
    @Autowired
    orderMapper ordermapper;

    @Override
    public orderVo createOrder(order order) {
        int insert = ordermapper.insert(order);
        if (insert != 0) {
            List<order> orders = ordermapper.selectList(null);
            for (order o : orders) {
                goods goods = goodsMapper.getGoodsByGoodsId(o.getGoods_id());
                SeckillGoods seckillGoods = seckillGoodsMapper.getSeckillByGoodsId(o.getGoods_id());
                orderVo orderVo = new orderVo();
                orderVo.setOrderId(String.valueOf(o.getId()));
                orderVo.setUserId(o.getUser_id());
                orderVo.setGoodsId(o.getGoods_id());
                orderVo.setTelephone(o.getTelephone());
                orderVo.setAddress(o.getAddress());
                orderVo.setImgPath(goods.getImg_path());
                orderVo.setSeckillPrice(seckillGoods.getSeckill_price());
                return orderVo;
            }
        }
        return null;

    }
}
